<template>
  <div class="data-analysis">
    <div class="page-header">
      <h2>数据分析</h2>
      <p>企业运营数据深度分析与洞察</p>
    </div>
    
    <div class="analysis-content">
      <!-- 关键指标卡片 -->>
      <div class="kpi-cards">
        <div class="kpi-card">
          <div class="kpi-icon" style="background: #409eff;">📈</div>
          <div class="kpi-info">
            <h3>销售增长率</h3>
            <p class="kpi-value positive">+15.8%</p>
            <span class="kpi-trend">较上月增长</span>
          </div>
        </div>
        
        <div class="kpi-card">
          <div class="kpi-icon" style="background: #67c23a;">💰</div>
          <div class="kpi-info">
            <h3>利润率</h3>
            <p class="kpi-value">23.5%</p>
            <span class="kpi-trend">保持稳定</span>
          </div>
        </div>
        
        <div class="kpi-card">
          <div class="kpi-icon" style="background: #e6a23c;">👥</div>
          <div class="kpi-info">
            <h3>客户满意度</h3>
            <p class="kpi-value positive">92.3%</p>
            <span class="kpi-trend">较上月提升</span>
          </div>
        </div>
        
        <div class="kpi-card">
          <div class="kpi-icon" style="background: #f56c6c;">⚡</div>
          <div class="kpi-info">
            <h3>运营效率</h3>
            <p class="kpi-value negative">-2.1%</p>
            <span class="kpi-trend">需要关注</span>
          </div>
        </div>
      </div>
      
      <!-- 分析图表区域 -->
      <div class="charts-grid">
        <div class="chart-card large">
          <div class="chart-header">
            <h3>销售趋势分析</h3>
            <div class="chart-controls">
              <select v-model="selectedPeriod" @change="updateCharts">
                <option value="7d">最近7天</option>
                <option value="30d">最近30天</option>
                <option value="90d">最近90天</option>
                <option value="1y">最近1年</option>
              </select>
            </div>
          </div>
          <div class="chart-content">
            <div class="chart-placeholder">
              <p>销售趋势图表 ({{ selectedPeriod }})</p>
            </div>
          </div>
        </div>
        
        <div class="chart-card">
          <div class="chart-header">
            <h3>客户分布</h3>
          </div>
          <div class="chart-content">
            <div class="chart-placeholder">
              <p>客户地域分布图</p>
            </div>
          </div>
        </div>
        
        <div class="chart-card">
          <div class="chart-header">
            <h3>产品销量排行</h3>
          </div>
          <div class="chart-content">
            <div class="chart-placeholder">
              <p>产品销量排行榜</p>
            </div>
          </div>
        </div>
        
        <div class="chart-card">
          <div class="chart-header">
            <h3>库存周转率</h3>
          </div>
          <div class="chart-content">
            <div class="chart-placeholder">
              <p>库存周转率分析</p>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 数据洞察 -->
      <div class="insights-section">
        <div class="section-header">
          <h3>数据洞察</h3>
          <span class="update-time">更新时间: {{ updateTime }}</span>
        </div>
        
        <div class="insights-grid">
          <div class="insight-card" v-for="insight in insights" :key="insight.id">
            <div class="insight-icon" :class="insight.type">{{ insight.icon }}</div>
            <div class="insight-content">
              <h4>{{ insight.title }}</h4>
              <p>{{ insight.description }}</p>
              <div class="insight-action">
                <button class="action-btn" @click="viewInsight(insight)">查看详情</button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DataAnalysis',
  data() {
    return {
      selectedPeriod: '30d',
      updateTime: '2024-01-15 14:30:00',
      insights: [
        {
          id: 1,
          type: 'positive',
          icon: '🎯',
          title: '销售目标达成率提升',
          description: '本月销售目标达成率为108.5%，较上月提升12.3个百分点，主要得益于新客户开发和老客户复购率提升。'
        },
        {
          id: 2,
          type: 'warning',
          icon: '⚠️',
          title: '库存积压风险',
          description: '部分产品库存周转天数超过60天，建议及时调整采购计划和促销策略，避免库存积压。'
        },
        {
          id: 3,
          type: 'info',
          icon: '💡',
          title: '客户行为分析',
          description: '客户购买行为呈现季节性特征，建议根据历史数据制定差异化的营销策略。'
        },
        {
          id: 4,
          type: 'positive',
          icon: '📊',
          title: '利润率优化机会',
          description: '通过优化供应链和提升运营效率，预计可将整体利润率提升3-5个百分点。'
        }
      ]
    }
  },
  methods: {
    updateCharts() {
      console.log('更新图表数据:', this.selectedPeriod)
    },
    
    viewInsight(insight) {
      console.log('查看洞察详情:', insight.title)
    }
  }
}
</script>

<style scoped>
.data-analysis {
  padding: 20px;
  background: #f5f7fa;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 30px;
}

.page-header h2 {
  margin: 0 0 8px 0;
  color: #303133;
  font-size: 24px;
}

.page-header p {
  margin: 0;
  color: #909399;
  font-size: 14px;
}

.kpi-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.kpi-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 15px;
}

.kpi-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
}

.kpi-info h3 {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: #909399;
  font-weight: normal;
}

.kpi-value {
  margin: 0 0 4px 0;
  font-size: 24px;
  font-weight: bold;
  color: #303133;
}

.kpi-value.positive {
  color: #67c23a;
}

.kpi-value.negative {
  color: #f56c6c;
}

.kpi-trend {
  font-size: 12px;
  color: #909399;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.chart-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chart-card.large {
  grid-column: span 2;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.chart-header h3 {
  margin: 0;
  font-size: 16px;
  color: #303133;
}

.chart-controls select {
  padding: 6px 12px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  background: white;
  font-size: 12px;
}

.chart-content {
  height: 250px;
}

.chart-placeholder {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  border-radius: 4px;
  color: #909399;
}

.insights-section {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.section-header h3 {
  margin: 0;
  font-size: 18px;
  color: #303133;
}

.update-time {
  font-size: 12px;
  color: #909399;
}

.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.insight-card {
  border: 1px solid #ebeef5;
  border-radius: 8px;
  padding: 20px;
  display: flex;
  gap: 15px;
}

.insight-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.insight-icon.positive {
  background: #f0f9ff;
  color: #67c23a;
}

.insight-icon.warning {
  background: #fdf6ec;
  color: #e6a23c;
}

.insight-icon.info {
  background: #f0f9ff;
  color: #409eff;
}

.insight-content {
  flex: 1;
}

.insight-content h4 {
  margin: 0 0 8px 0;
  font-size: 16px;
  color: #303133;
}

.insight-content p {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: #606266;
  line-height: 1.5;
}

.action-btn {
  padding: 6px 12px;
  background: #409eff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.action-btn:hover {
  background: #337ecc;
}
</style>